package com.zengjunjian.blog_system.web.client;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

//用户登录模块
@Controller
public class LoginController {
    //向登陆页面跳转,同时封装原始页面地址
    @GetMapping(value = "/login")
    public String login(HttpServletRequest request, Map map){
        //分别获取请求头和参数URL中的原始非拦截的访问路径
        String referer = request.getHeader("Referer");
        String url = request.getParameter("url");
        //如果参数url中已经封装了原始页面路径，直接返回该路径
        if(url!=null && !url.equals("")){
            map.put("url",url);
            //如果请求头本身包含登录，将重定向url为空，让后台通过用户角色进行选择跳转
        }else {
            map.put("url",referer);
        }
        return "comm/login";
    }
    //对Security拦截的无权限访问异常处理路径映射
    @GetMapping(value = "/errorPage/{page}/{code}")
    public String AccessExceptionHandler(@PathVariable("page")String page,@PathVariable("code")String code){
        return page+"/"+code;
    }
}
